4 * @subpackage SpecialPage
8 * Special page "user contributions".
9 * Shows a list of the contributions of a user.
12 * @param string $par (optional) user name of the user for which to show the contributions
14 function wfSpecialContributions( $par = null ) {
15 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
16 $fname = 'wfSpecialContributions';
19 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
20 $namespace = $wgRequest->getIntOrNull( 'namespace' );
21 $invert = $wgRequest->getBool( 'invert' );
22 $hideminor = ($wgRequest->getBool( 'hideminor' ) ?
true : false);
24 if ( '' == $target ) {
25 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29 # FIXME: Change from numeric offsets to date offsets
30 list( $limit, $offset ) = wfCheckLimits( 50, '' );
31 $querylimit = $limit +
1;
32 $sk = $wgUser->getSkin();
33 $dbr =& wfGetDB( DB_SLAVE
);
36 $nt = Title
::newFromURL( $target );
38 $wgOut->errorpage( 'notargettitle', 'notargettext' );
41 $nt =& Title
::makeTitle( NS_USER
, $nt->getDBkey() );
43 $id = User
::idFromName( $nt->getText() );
48 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
49 $userCond = '=' . $id;
51 $talk = $nt->getTalkPage();
53 $ul .= ' (' . $sk->makeLinkObj( $talk, $wgLang->getNsText( NS_TALK
) ) . ')';
57 if ( $target == 'newbies' ) {
58 # View the contributions of all recently created accounts
59 $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
60 $userCond = '>' . ($max - $max / 100);
61 $ul = wfMsg ( 'newbies' );
65 $wgOut->setSubtitle( wfMsgHtml( 'contribsub', $ul ) );
67 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
68 $mlink = $sk->makeKnownLinkObj( $contribsPage,
69 $hideminor ?
wfMsgHtml( 'show' ) : wfMsgHtml( 'hide' ),
71 'target' => $nt->getPrefixedDbKey(),
74 'hideminor' => $hideminor ?
0 : 1,
75 'namespace' => $namespace ) ) );
77 $minorQuery = $hideminor ?
"AND rev_minor_edit=0" : "";
78 if( !is_null($namespace) ) {
79 $minorQuery .= ' AND page_namespace ' . ($invert ?
'!' : '') . "= {$namespace}";
82 extract( $dbr->tableNames( 'page', 'revision' ) );
83 if ( $userCond == "" ) {
84 $condition = "rev_user_text=" . $dbr->addQuotes( $nt->getText() );
85 $index = 'usertext_timestamp';
87 $condition = "rev_user {$userCond}";
88 $index = 'user_timestamp';
92 $use_index = $dbr->useIndexClause( $index );
94 page_namespace,page_title,page_is_new,page_latest,
95 rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text,
97 FROM $page,$revision $use_index
98 WHERE page_id=rev_page AND $condition $minorQuery " .
99 "ORDER BY rev_timestamp DESC " . $dbr->limitResult( $querylimit, $offset );
100 $res = $dbr->query( $sql, $fname );
101 $numRows = $dbr->numRows( $res );
103 $wgOut->addHTML( ucNamespaceForm( $target, $hideminor, $namespace, $invert ) );
105 $top = wfShowingResults( $offset, $limit );
106 $wgOut->addHTML( "<p>{$top}\n" );
108 $sl = wfViewPrevNext( $offset, $limit,
109 $wgContLang->specialpage( "Contributions" ),
110 "hideminor=$hideminor&namespace=$namespace&invert=$invert&target=" . wfUrlEncode( $target ),
111 ($numRows) <= $limit);
113 $shm = wfMsgHtml( "showhideminor", $mlink );
114 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
117 if ( 0 == $numRows ) {
118 $wgOut->addWikiText( wfMsg( "nocontribs" ) );
122 $wgOut->addHTML( "<ul>\n" );
124 while( $obj = $dbr->fetchObject( $res ) ) {
125 if( ++
$n > $limit ) {
126 // Extra row for determining 'next'ability, don't display
129 $wgOut->addHTML( ucListEdit( $sk, $obj ) );
131 $dbr->freeResult( $res );
132 $wgOut->addHTML( "</ul>\n" );
134 $wgOut->addHTML( "<br />{$sl} ($shm)\n");
139 * Generates each row in the contributions list.
141 * Contributions which are marked "top" are currently on top of the history.
142 * For these contributions, a [rollback] link is shown for users with sysop
143 * privileges. The rollback link restores the most recent version that was not
144 * written by the target user.
146 * If the contributions page is called with the parameter &bot=1, all rollback
147 * links also get that parameter. It causes the edit itself and the rollback
148 * to be marked as "bot" edits. Bot edits are hidden by default from recent
149 * changes, so this allows sysops to combat a busy vandal without bothering
152 * @todo This would probably look a lot nicer in a table.
154 function ucListEdit( $sk, $row ) {
155 $fname = 'ucListEdit';
156 wfProfileIn( $fname );
158 global $wgLang, $wgOut, $wgUser, $wgRequest;
160 if( !isset( $messages ) ) {
161 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
162 $messages[$msg] = wfMsg( $msg );
166 $page =& Title
::makeTitle( $row->page_namespace
, $row->page_title
);
167 $link = $sk->makeKnownLinkObj( $page, '' );
168 $difftext = $topmarktext = '';
169 if( $row->rev_id
== $row->page_latest
) {
170 $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
171 if( !$row->page_is_new
) {
172 $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
174 $difftext .= $messages['newarticle'];
177 if( $wgUser->isAllowed('rollback') ) {
178 $extraRollback = $wgRequest->getBool( 'bot' ) ?
'&bot=1' : '';
179 $extraRollback .= '&token=' . urlencode(
180 $wgUser->editToken( array( $page->getPrefixedText(), $row->rev_user_text
) ) );
181 $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
182 $messages['rollbacklink'],
183 'action=rollback&from=' . urlencode( $row->rev_user_text
) . $extraRollback ) .']';
187 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
188 $difftext = '(' . $messages['diff'] . ')';
190 $difftext = $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$row->rev_id
);
192 $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
194 $comment = $sk->commentBlock( $row->rev_comment
, $page );
195 $d = $wgLang->timeanddate( $row->rev_timestamp
, true );
197 if( $row->rev_minor_edit
) {
198 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
203 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
204 if( $row->rev_deleted
) {
205 $ret = '<span class="deleted">' . $ret . '</span> ' . htmlspecialchars( wfMsg( 'deletedrev' ) );
207 $ret = "<li>$ret</li>\n";
208 wfProfileOut( $fname );
213 * Generates a form used to restrict display of contributions
214 * to a specific namespace
217 * @param string $target target user to show contributions for
218 * @param string $hideminor whether minor contributions are hidden
219 * @param string $namespace currently selected namespace, NULL for show all
220 * @param bool $invert inverts the namespace selection on true (default null)
222 function ucNamespaceForm ( $target, $hideminor, $namespace, $invert ) {
223 global $wgContLang, $wgScript;
225 $namespaceselect = "<select name='namespace' id='nsselectbox'>";
226 $namespaceselect .= '<option value="" '.(is_null($namespace) ?
' selected="selected"' : '').'>'.wfMsgHtml( 'contributionsall' ).'</option>';
227 $arr = $wgContLang->getFormattedNamespaces();
228 foreach( $arr as $ns => $name ) {
231 $n = $ns === NS_MAIN ?
wfMsgHtml( 'blanknamespace' ) : htmlspecialchars( $name );
232 $sel = $namespace == $ns ?
' selected="selected"' : '';
233 $namespaceselect .= "<option value='$ns'$sel>$n</option>";
235 $namespaceselect .= '</select>';
237 $action = htmlspecialchars( $wgScript );
238 $out = "<div class='namespaceselector'><form method='get' action=\"$action\">";
239 $out .= '<input type="hidden" name="title" value="' . htmlspecialchars( $wgContLang->specialpage( 'Contributions' ) ) . '" />';
240 $out .= '<input type="hidden" name="target" value="' . htmlspecialchars( $target ) . '" />';
241 $out .= '<input type="hidden" name="hideminor" value="' . ( $hideminor ?
1 : 0 ) .'" />';
243 <div id='nsselect' class='contributions'>
244 <label for='nsselectbox'>" . wfMsgHtml('namespace') . "</label>
246 <input type='submit' value=\"" . wfMsgHtml( 'allpagessubmit' ) . "\" />
247 <input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ?
' checked="checked"' : '' ) . " />
248 <label for='nsinvert'>" . wfMsgHtml('invert') . "</label>
250 $out .= '</form></div>';